<?php

/**
 * Updates insertion and edition handler
 * @package ModuleAssistance
 * @version 1.0b
 */

session_start();

// Configuration file
include 'configuration.php';
// Functions
include 'inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	header('Location: index.php');
	exit();
endif;

// Include all objects
foreach (glob($configuration['webroot'].'objects/*.php') as $class) { include_once $class; }

// ---------- START: HEAD
include $configuration['webroot'].'inc/head.php';
// ---------- END: HEAD

// ---------- START: MENU
include $configuration['webroot'].'inc/menu.php';
// ---------- END: MENU

// ---------- START: BODY

if (isset($_GET['operation'])) :

	$update = new Update();
	
	// In case we are in an insert state
	if ($_GET['operation'] == 'add'):
		$supportcase = new SupportCase();
		if (isset($_GET['sid'])) $supportcase->Get($_GET['sid']);
		$update->SetSupportcase($supportcase);
		$crmuser = unserialize($_SESSION['current_user']);
		$update->SetCrmuser($crmuser);
		$contact = $crmuser->GetContact();
	
	// In case we are in an update state
	elseif (($_GET['operation'] == 'edit') && isset($_GET['id'])):
		$update->Get($_GET['id']);
		$supportcase = $update->GetSupportcase();
		$crmuser = $update->GetCrmuser();
		$contact = $crmuser->GetContact();
	endif;

	include 'forms/update.php';

endif;
// ---------- END: BODY

// ---------- START: FOOT
include $configuration['webroot'].'inc/foot.php';
// ---------- END: FOOT

// ---------- JAVASCRIPTS AND END
include $configuration['webroot'].'inc/js.php'; ?>
<script type="text/javascript" src="js/updates.js"></script>

</body>
</html>